<?PHP
// vim: set expandtab tabstop=4 shiftwidth=4:
// +----------------------------------------------------------------------+
// | SAPID: XML Sapiens Engine Demonstrator                               |
// +----------------------------------------------------------------------+
// | Author:  Linur (Pavel Levkovich)					                  |
// | Copyright (c) 2004 Linur											  |
// | http://sapid.sourceforge.net	                                      |
// +----------------------------------------------------------------------+
// | This source file is free software; you can redistribute it and/or    |
// | modify it under the terms of the GNU Lesser General Public           |
// | License as published by the Free Software Foundation; either         |
// | version 2.1 of the License, or (at your option) any later version.   |
// |                                                                      |
// | This source file is distributed in the hope that it will be useful,  |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    |
// | Lesser General Public License for more details.                      |
// +----------------------------------------------------------------------+
// Release: 11.04.05 (dd/mm/yy) Linur (Pavel Levkovich)
// $Id: stats.inc.php,v 1.4 2006/05/25 08:51:54 toxin76 Exp $

function convertRefer($line) {
	if(	!preg_match("/yandex\.ru/is", $line) AND
	!preg_match("/ya\.ru/is", $line) AND
	!preg_match("/rambler\.ru/is", $line)
	) return $line;

	return $line;
	/*
	if(function_exists("iconv"))
	return iconv("Windows-1251", "UTF-8", $line);
	else
	return mb_convert_encoding($line, "Windows-1251", "UTF-8");
	*/
}

if (!defined("SAPID_STARTED")) die("Hacking attempt!");

if (!$_GET["mode"]) $graphMode=1; else $graphMode=$_GET["mode"];

if ($_GET["table"] && !$_GET["graph"]){


	if($_GET["delete"]) { @unlink($root_path . "log/".$_GET["delete"]); }

	$d = dir($root_path . "log/");
	$logs = array();
	while (false !== ($entry = $d->read())) {
		if ($entry!="." and $entry!=".." and strstr($entry,".log")) $logs[$entry]="<a href=\"?option=stats&table=true&date=".preg_replace("/\.log$/", "", $entry)."\">" . $entry . "</a>&nbsp; <a href=\"".$http_path."?option=stats&table=true&delete=".$entry."\" onClick=\"return confirm('".$lang["confirm_delete"]."')\"><img src=\"".$http_path."usr/system/images/delete.gif\" alt=\"".$lang["Delete"]."\" width=\"12\" hight=\"14\" border=\"0\" /></a>";
	}
	$d->close();
	ksort($logs);
	$logs = implode('<br/>',$logs);
	$panel=
	''."
<table cellspacing=0 cellpadding=0 width=\"100%\"><tr><td style=\"width: 150px; vertical-align: top; background-color: #B5D1E4; font-size: 12px; border-right: 1px solid #CEE4F2; \">
			<div style=\" height: 28px; background-color: #A2C3D8; border-bottom: 1px solid #CEE4F2; font-size: 12px; padding: 6px 0px 0px 20px;\"><b>".$lang["Archive"]."</b></div>
			<div style=\"padding: 5px 0px 0px 20px;\">".$logs."</div>
			</td><td>
			<table class=\"tpanel\" cellspacing=0 cellpadding=0>
			<tr><td class=\"header\"><B>".$lang["time"]."</B></td><td class=\"header\"><B>".$lang["IP"]."</B></td><td class=\"header\"><B>".wordwrap($lang["Request"],50,"\n",1)."</B></td><td class=\"header\"><B>".$lang["Referrer"]."</B></td><td class=\"header\"><B>".$lang["Browser"]."</B></td><td class=\"header\"><B>".$lang["OS"]."</B></td></tr>
			";
	if ($_GET["date"]) $date=$_GET["date"]; else $date=date("Y.m.d");
	$stats=@file($root_path . "log/" . $date.".log");
	if ($stats)
	foreach ($stats as $entry) {
		$arr = split("\|", $entry);
		$ip[] = $arr[1];
		$arr[3] = convertRefer($arr[3]);
		$request = "<a href=\"".trim($arr[2])."\" title=\"".trim($arr[2])."\" target=\"_blank\">".substr(trim($arr[2]),0,20)."...</a>";
		$reffer = "<a href=\"".trim($arr[3])."\" title=\"".trim($arr[3])."\" target=\"_blank\">".substr(trim($arr[3]),0,20)."...</a>";
		if(!trim($arr[3])) $reffer = "";
		$panel.=preg_replace("/(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|/", "<tr><td>\\1</td><td>\\2</td><td>".$request."</td><td>&nbsp;".$reffer."</td><td>\\5</td><td style=\"padding-right: 10px;\">\\6</td></tr>\r\n", $entry);
	}

	if(count($ip)>0) $_total = count(array_unique($ip));
	$total = '<b style="font-size: 12px;">'.$lang["_Total"].': '.(int)$_total.' ip, '.count($stats).' '.strtolower($lang["Hits"]).'</b>';

	$panel='
			
		<div style="margin-top: 3px;" class="panel">
		<div style="padding-left: 20px; padding-bottom: 10px; ">
			'.$lang["StatisticInterfaceDewscription"].'
		<br /><br />'.$total.'<br />
		</div>
		
		' . $panel . "</table></td></tr></table></div>";

} elseif ($_GET["date_start"] && !$_GET["graph"]){

	$d = dir($root_path . "log/");
	while (false !== ($entry = $d->read())) {
		if ($entry!="." and $entry!=".." and strstr($entry,".log") and (substr($entry,0,10)>$_GET["date_start"])) {
			$stats=@file($root_path . "log/" . $entry);
			if ($stats){
				foreach ($stats as $entryDat) {
					$arr = split("\|", $entryDat);
					if (trim($arr[4]) != "Bot") {
						$allIP[] = $arr[1];
						$allPages[] = $arr[2];
					}
					$allSystems[] = $arr[5];
					$allBrowsers[] = $arr[4];
					$arr[3]=convertRefer($arr[3]);
					$allReff[] = $arr[3];
				}
			}
		}

	}

	$d->close();
	$diffBrowsers=sort(@array_count_values($allBrowsers));
	$d_month = date("Y.m.d", time()-30*24*60*60);
	$d_week = date("Y.m.d", time()-7*24*60*60);
	$d_day = date("Y.m.d", time()-24*60*60);
	$cnSel="<div style=\"float: right; padding-right: 20px\">
	<a href=\"".$env["http_path"]."?option=stats&date_start=1970.01.01\">".$lang["For_all_time"]."</a> | 
	<a href=\"".$env["http_path"]."?option=stats&date_start=".$d_month."\">".$lang["For_a_month"]."</a> | 
	<a href=\"".$env["http_path"]."?option=stats&date_start=".$d_week."\">".$lang["For_a_week"]."</a> | 
	<a href=\"".$env["http_path"]."?option=stats&date_start=".$d_day."\">".$lang["For_a_day"]."</a></div>";
	$cn="<table cellspacing=0 cellpadding=0 style=\"width: 100%\"><tr>";

	$cn.="<td width=\"50%\" style='border-right: solid 1px #CEE4F2'><div style='border-bottom: solid 1px #A2C3D8; padding-left: 20px; cursor: pointer; font-weight: bold; font-size: 12px' onClick='if (document.getElementById(\"brStats\").style.display==\"none\") document.getElementById(\"brStats\").style.display=\"block\"; else document.getElementById(\"brStats\").style.display=\"none\"; '>".$lang["Browsers_stats"]."</div>
	<div id='brStats'>";
	$cn.="<table class=\"tpanel\" cellspacing=0 cellpadding=0 style=\"width: 100%\">";
	$cn.="<tr><td class=\"header\"><b>".$lang["Browser"]."</b></td>
	<td class=\"header\" style=\"padding-right: 20px\" nowrap><b>".$lang["Visits_number"]."</b></td></tr>";
	$diffPages=@array_count_values($allBrowsers);
	arsort($diffPages);
	foreach ($diffPages as $key=>$value){
		$cn.="<tr><td><a href='$key' target='_blank'>$key</a></td><td style=\"padding-right: 20px\">$value</td></tr>";
	}
	$cn.="</table></div></td>";

	$cn.="<td width=\"50%\"><div style='border-bottom: solid 1px #A2C3D8; padding-left: 20px; cursor: pointer; font-weight: bold; font-size: 12px' onClick='if (document.getElementById(\"sysStats\").style.display==\"none\") document.getElementById(\"sysStats\").style.display=\"block\"; else document.getElementById(\"sysStats\").style.display=\"none\"; '>".$lang["Systems_statistics"]."</div><div id='sysStats'>";
	$cn.="<table class=\"tpanel\" cellspacing=0 cellpadding=0 style=\"width: 100%\">";
	$cn.="<tr><td class=\"header\"><b>".$lang["System"]."</b></td>
	<td class=\"header\" style=\"padding-right: 20px\" nowrap><b>".$lang["Visits_number"]."</b></td></tr>";
	$diffPages=@array_count_values($allSystems);
	arsort($diffPages);
	foreach ($diffPages as $key=>$value){
		$cn.="<tr><td><a href='$key' target='_blank'>$key</a></td><td style=\"padding-right: 20px\">$value</td></tr>";
	}
	$cn.="</table></div></td>";

	$cn.="</tr><tr><td colspan=\"2\">&nbsp;</td></tr><tr>";


	$cn.="<td width=\"50%\" style='border-right: solid 1px #CEE4F2'><div style='border-bottom: solid 1px #A2C3D8; padding-left: 20px; cursor: pointer; font-weight: bold; font-size: 12px' onClick='if (document.getElementById(\"pageStats\").style.display==\"none\") document.getElementById(\"pageStats\").style.display=\"block\"; else document.getElementById(\"pageStats\").style.display=\"none\"; '>".$lang["Pages_statistics"]."</div><div id='pageStats'>";
	$cn.="<table class=\"tpanel\" cellspacing=0 cellpadding=0 style=\"width: 100%\">";
	$cn.="<tr><td class=\"header\"><b>".$lang["Address"]."</b></td><td class=\"header\" style=\"padding-right: 20px\" nowrap><b>".$lang["Visits_number"]."</b></td></tr>";
	$diffPages=@array_count_values($allPages);
	arsort($diffPages);
	foreach ($diffPages as $key=>$value){
		$cn.="<tr><td><a href='$key' target='_blank'>".wordwrap($key,50,"\n",1)."</a></td><td style=\"padding-right: 20px\">$value</td></tr>";
	}
	$cn.="</table></div></td>";

	$cn.="<td width=\"50%\"><div style='border-bottom: solid 1px #A2C3D8; padding-left: 20px; cursor: pointer; font-weight: bold; font-size: 12px' onClick='if (document.getElementById(\"reffStats\").style.display==\"none\") document.getElementById(\"reffStats\").style.display=\"block\"; else document.getElementById(\"reffStats\").style.display=\"none\"; '>".$lang["Jumps_number"]."</div><div id='reffStats'>";
	$cn.="<table class=\"tpanel\" cellspacing=0 cellpadding=0 style=\"width: 100%\">";
	$cn.="<tr><td class=\"header\"><b>".$lang["Address"]."</b></td><td class=\"header\" style=\"padding-right: 20px\" nowrap><b>".$lang["Jumps_number"]."</b></td></tr>";
	$diffPages=@array_count_values($allReff);
	arsort($diffPages);
	foreach ($diffPages as $key=>$value){
		if (trim($key)!="") $cn.="<tr><td><a href='$key' target='_blank'>".wordwrap($key,50,"\n",1)."</a></td><td style=\"padding-right: 20px\">$value</td></tr>";
	}
	$cn.="</table></div></td>";


	$cn.="</tr></table>";
	$totalAll= "<div style='font-size: 12px; padding: 10px 20px 5px 20px; background: #A2C3D8; margin: 0px 0px 10px 0px; font-weight: bold'>".$cnSel.$lang["Report_since"]." <i>".$_GET["date_start"]."</i><br />".$lang["Unique_IPs"].": <i>".count(array_unique($allIP))."</i>&nbsp;&nbsp;|&nbsp;&nbsp;".$lang["Hits"].": <i>".count($allIP)."</i></div>".$cn;

	$panel=$totalAll."<div style='height: 50px'>&nbsp;</div>";

} else if ($_GET["date_start"]==$_GET["date_end"] && $_GET["graph"]){

	if ($_GET["date_start"]) $date_start=$_GET["date_start"];
	else $date_start = date("Y.m.d", time()-30*24*60*60);

	if ($_GET["date_end"]) $date_end=$_GET["date_end"];
	else $date_end = date("Y.m.d", time());

	$stats=@file($root_path . "log/".$_GET["date_start"].".log");
	if ($stats){
		$allStr= Array();
		$i==0;
		foreach ($stats as $entryDat) {
			$arr = split("\|", $entryDat);
			if (trim($arr[4]) != "Bot"){
				if (!$allStr[substr($arr[0],11,2)]){
					$allStr[substr($arr[0],11,2)] = Array();
				}
				$allStr[substr($arr[0],11,2)][] = $arr[1];
				$i++;
			}
		}
	}
	$total= Array();

	for ($i=0; $i<24; $i++){
		$ii=($i<=9)?("0".$i):$i;
		if (!$allStr[$ii]) $allStr[$ii]= Array();
		$total[$ii]["IP"]=count(array_unique($allStr[$ii]));
		$total[$ii]["HIT"]=count($allStr[$ii]);
	}
	$graphFile=@fopen($root_path . "usr/dump/graph.log", "w");

	$cn="<div style='width: 580px; padding-top: 10px; border-bottom: solid 1px #A2C3D8; padding-left: 20px; cursor: pointer; font-weight: bold; font-size: 12px' onClick='if (document.getElementById(\"tableStats\").style.display==\"none\") document.getElementById(\"tableStats\").style.display=\"block\"; else document.getElementById(\"tableStats\").style.display=\"none\"; '><div style=\"width: 40px; border: solid 1px #A2C3D8; margin: 4px; padding: 3px;\">".$lang["ieeditor"]["Table"]."...</div></div>";
	$cn.="<table class=\"tpanel\" cellspacing=0 cellpadding=0 style=\"width:600px; display: none\" id=\"tableStats\">";
	$cn.="<tr>	<td class=\"header\"><b>".$lang["Date"]."</b></td>
				<td class=\"header\" style=\"padding-right: 10px; text-align: center\" nowrap><b>".$lang["Unique_IPs"]."</b></td>
				<td class=\"header\" style=\"padding-right: 10px; text-align: center\" nowrap><b>".$lang["Hits"]."</b></td></tr>";
	if ($total){
		ksort($total);
		foreach ($total as $key=>$value){

			$cn.="<tr>";
			$cn.="<td><b>".$key."</b></td>";
			$cn.="<td style=\"text-align: center\">".$value["IP"]."</td>";
			fwrite($graphFile,$key." ".$value["IP"]." ".$value["HIT"]."\r\n");
			$cn.="<td style=\"text-align: center\">".$value["HIT"]."</td>";
			$cn.="</tr>";
		}
	}
	$cn.="</table>";
	fclose($graphFile);

	$selectorYearStart="";
	for ($i=date("Y", time())-5; $i<=date("Y", time()); $i++)
	$selectorYearStart.="<option value=\"".$i."\" ".(($i==substr($date_start,0,4))?"selected":"").">".$i."</option>\r\n";

	$selectorMonthStart="";
	for ($i=1; $i<=12; $i++)
	$selectorMonthStart.="<option value=\"".($i<10?"0".$i:$i)."\" ".(($i==substr($date_start,5,2))?"selected":"").">".($i<10?"0".$i:$i)."</option>\r\n";

	$selectorDayStart="";
	for ($i=1; $i<=31; $i++)
	$selectorDayStart.="<option value=\"".($i<10?"0".$i:$i)."\" ".(($i==substr($date_start,8,2))?"selected":"").">".($i<10?"0".$i:$i)."</option>\r\n";

	$selectorYearEnd="";
	for ($i=date("Y", time())-5; $i<=date("Y", time()); $i++)
	$selectorYearEnd.="<option value=\"".$i."\" ".(($i==substr($date_end,0,4))?"selected":"").">".$i."</option>\r\n";

	$selectorMonthEnd="";
	for ($i=1; $i<=12; $i++)
	$selectorMonthEnd.="<option value=\"".($i<10?"0".$i:$i)."\" ".(($i==substr($date_end,5,2))?"selected":"").">".($i<10?"0".$i:$i)."</option>\r\n";

	$selectorDayEnd="";
	for ($i=1; $i<=31; $i++)
	$selectorDayEnd.="<option value=\"".($i<10?"0".$i:$i)."\" ".(($i==substr($date_end,8,2))?"selected":"").">".($i<10?"0".$i:$i)."</option>\r\n";

	$selector="<form name=\"selector\" action=\"".$env["http_path"]."\" method=\"get\" onSubmit=\"document.selector.date_start.value=document.selector.yearStart.value+'.'+document.selector.monthStart.value+'.'+document.selector.dayStart.value; document.selector.date_end.value=document.selector.yearEnd.value+'.'+document.selector.monthEnd.value+'.'+document.selector.dayEnd.value; \">";
	$selector.="<input type=\"hidden\" name=\"option\" value=\"stats\" />";
	$selector.="<input type=\"hidden\" name=\"graph\" value=\"true\" />";
	$selector.="<input type=\"hidden\" name=\"date_start\" value=\"\" />";
	$selector.="<input type=\"hidden\" name=\"date_end\" value=\"\" />";

	$selector.="<div style='background: #A2C3D8; width: 578px; padding: 5px 0px 5px 20px; font-size: 12px'>
	".$lang["Select"]."&nbsp;";
	$month_start = $env["http_path"]."?option=stats&graph=true&date_start=".date("Y.m.d", time()-30*24*60*60);
	$week_start = $env["http_path"]."?option=stats&graph=true&date_start=".date("Y.m.d", time()-6*24*60*60);
	$day_start =  $env["http_path"]."?option=stats&graph=true&date_start=".date("Y.m.d", time())."&date_end=".date("Y.m.d", time());
	$yesterday_start =  $env["http_path"]."?option=stats&graph=true&date_start=".date("Y.m.d", time()-24*60*60)."&date_end=".date("Y.m.d", time()-24*60*60);
	$selector.="<a style=\"font-size: 12px\" href=\"$day_start\">".$lang["For_today"]."</a>, <a style=\"font-size: 12px\" href=\"$yesterday_start\">".$lang["For_yesterday"]."</a>, <a style=\"font-size: 12px\" href=\"$week_start\">".$lang["For_a_week"]."</a>, <a style=\"font-size: 12px\" href=\"$month_start\">".$lang["For_a_month"]."</a>";
	$selector.="<div style=\"margin:15px;\"></div> ".$lang["since"].":&nbsp;";
	$selector.="<select name=\"dayStart\">";
	$selector.=$selectorDayStart;
	$selector.="</select>.";
	$selector.="<select name=\"monthStart\">";
	$selector.=$selectorMonthStart;
	$selector.="</select>.";
	$selector.="<select name=\"yearStart\">";
	$selector.=$selectorYearStart;
	$selector.="</select>&nbsp;";
	$selector.="&nbsp;&nbsp;".$lang["to"].":&nbsp;";
	$selector.="<select name=\"dayEnd\">";
	$selector.=$selectorDayEnd;
	$selector.="</select>.";
	$selector.="<select name=\"monthEnd\">";
	$selector.=$selectorMonthEnd;
	$selector.="</select>.";
	$selector.="<select name=\"yearEnd\">";
	$selector.=$selectorYearEnd;
	$selector.="</select>&nbsp;&nbsp;";
	$selector.="<input type=\"submit\" class=\"sapidcms_cont_btn\" value=\"".$lang["Show"]."\">";
	$selector.="</div></form>";

	$image = "<div><img src=\"".$env["http_path"]."etc/interface/graph.php?picMode=".$graphMode."&title=Site: ".$env["http_path"]."\" width=\"600\" height=\"400\" /></div>";
	$panel=$selector.$image.$cn."<div style='height: 50px'>&nbsp;</div>";

} else {

	if ($_GET["date_start"]) $date_start=$_GET["date_start"];
	else $date_start = date("Y.m.d", time()-7*24*60*60);

	if ($_GET["date_end"]) $date_end=$_GET["date_end"];
	else $date_end = date("Y.m.d", time());

	$d = dir($root_path . "log/");
	$date_first=date("Y.m.d", time());
	while (false !== ($entry = $d->read())) {
		if ($entry!="." and $entry!=".." and strstr($entry,".log") and (substr($entry,0,10)>=$date_start) and (substr($entry,0,10)<=$date_end)) {
			if ($date_first>substr($entry,0,10)) $date_first=substr($entry,0,10);
			$stats=@file($root_path . "log/" . $entry);
			if ($stats){
				$allIP= Array();
				foreach ($stats as $entryDat) {
					$arr = split("\|", $entryDat);
					if (trim($arr[4]) != "Bot"){
						$allIP[] = $arr[1];


					}
				}

				$total[substr($entry,0,10)]["IP"]=count(array_unique($allIP));
				$total[substr($entry,0,10)]["HIT"]=count($allIP);
			}
		}

	}

	//d($total);
	$graphFile=@fopen($root_path . "usr/dump/graph.log", "w");
	$d->close();
	$cn="<div style='width: 580px; padding-top: 10px; border-bottom: solid 1px #A2C3D8; padding-left: 20px; cursor: pointer; font-weight: bold; font-size: 12px' onClick='if (document.getElementById(\"tableStats\").style.display==\"none\") document.getElementById(\"tableStats\").style.display=\"block\"; else document.getElementById(\"tableStats\").style.display=\"none\"; '><div style=\"width: 40px; border: solid 1px #A2C3D8; margin: 4px; padding: 3px;\">".$lang["ieeditor"]["Table"]."...</div></div>";
	$cn.="<table class=\"tpanel\" cellspacing=0 cellpadding=0 style=\"width:600px; display: none\" id=\"tableStats\">";

	$cn.="<tr>	<td class=\"header\"><b>".$lang["Date"]."</b></td>
				<td class=\"header\" style=\"padding-right: 10px; text-align: center\" nowrap><b>".$lang["Unique_IPs"]."</b></td>
				<td class=\"header\" style=\"padding-right: 10px; text-align: center\" nowrap><b>".$lang["Hits"]."</b></td></tr>";

	if ($total){
		ksort($total);
		foreach ($total as $key=>$value){
			$cn.="<tr>";
			$cn.="<td><b>".$key."</b></td>";
			$cn.="<td style=\"text-align: center\">".$value["IP"]."</td>";
			fwrite($graphFile,$key." ".$value["IP"]." ".$value["HIT"]."\r\n");
			$cn.="<td style=\"text-align: center\">".$value["HIT"]."</td>";
			$cn.="</tr>";
		}
	}
	$cn.="</table>";
	fclose($graphFile);
	$selectorYearStart="";
	for ($i=date("Y", time())-5; $i<=date("Y", time()); $i++)
	$selectorYearStart.="<option value=\"".$i."\" ".(($i==substr($date_start,0,4))?"selected":"").">".$i."</option>\r\n";

	$selectorMonthStart="";
	for ($i=1; $i<=12; $i++)
	$selectorMonthStart.="<option value=\"".($i<10?"0".$i:$i)."\" ".(($i==substr($date_start,5,2))?"selected":"").">".($i<10?"0".$i:$i)."</option>\r\n";

	$selectorDayStart="";
	for ($i=1; $i<=31; $i++)
	$selectorDayStart.="<option value=\"".($i<10?"0".$i:$i)."\" ".(($i==substr($date_start,8,2))?"selected":"").">".($i<10?"0".$i:$i)."</option>\r\n";

	$selectorYearEnd="";
	for ($i=date("Y", time())-5; $i<=date("Y", time()); $i++)
	$selectorYearEnd.="<option value=\"".$i."\" ".(($i==substr($date_end,0,4))?"selected":"").">".$i."</option>\r\n";

	$selectorMonthEnd="";
	for ($i=1; $i<=12; $i++)
	$selectorMonthEnd.="<option value=\"".($i<10?"0".$i:$i)."\" ".(($i==substr($date_end,5,2))?"selected":"").">".($i<10?"0".$i:$i)."</option>\r\n";

	$selectorDayEnd="";
	for ($i=1; $i<=31; $i++)
	$selectorDayEnd.="<option value=\"".($i<10?"0".$i:$i)."\" ".(($i==substr($date_end,8,2))?"selected":"").">".($i<10?"0".$i:$i)."</option>\r\n";

	$selector="<form name=\"selector\" action=\"".$env["http_path"]."\" method=\"get\" onSubmit=\"document.selector.date_start.value=document.selector.yearStart.value+'.'+document.selector.monthStart.value+'.'+document.selector.dayStart.value; document.selector.date_end.value=document.selector.yearEnd.value+'.'+document.selector.monthEnd.value+'.'+document.selector.dayEnd.value; \">";
	$selector.="<input type=\"hidden\" name=\"option\" value=\"stats\" />";
	$selector.="<input type=\"hidden\" name=\"graph\" value=\"true\" />";
	$selector.="<input type=\"hidden\" name=\"date_start\" value=\"\" />";
	$selector.="<input type=\"hidden\" name=\"date_end\" value=\"\" />";

	$selector.="<div style='background: #A2C3D8; width: 578px; padding: 5px 0px 5px 20px; font-size: 12px;'>".$lang["Select"].":&nbsp;";
	$month_start = $env["http_path"]."?option=stats&graph=true&date_start=".date("Y.m.d", time()-30*24*60*60);
	$week_start = $env["http_path"]."?option=stats&graph=true&date_start=".date("Y.m.d", time()-6*24*60*60);
	$day_start =  $env["http_path"]."?option=stats&graph=true&date_start=".date("Y.m.d", time())."&date_end=".date("Y.m.d", time());
	$yesterday_start =  $env["http_path"]."?option=stats&graph=true&date_start=".date("Y.m.d", time()-24*60*60)."&date_end=".date("Y.m.d", time()-24*60*60);
	$selector.="<a style=\"font-size: 12px\" href=\"$day_start\">".$lang["For_today"]."</a>, <a style=\"font-size: 12px\" href=\"$yesterday_start\">".$lang["For_yesterday"]."</a>, <a style=\"font-size: 12px\" href=\"$week_start\">".$lang["For_a_week"]."</a>, <a style=\"font-size: 12px\" href=\"$month_start\">".$lang["For_a_month"]."</a>";
	$selector.="<div style=\"margin:5px;\"></div> ".$lang["since"].":&nbsp;";
	$selector.="<select name=\"dayStart\">";
	$selector.=$selectorDayStart;
	$selector.="</select>.";
	$selector.="<select name=\"monthStart\">";
	$selector.=$selectorMonthStart;
	$selector.="</select>.";
	$selector.="<select name=\"yearStart\">";
	$selector.=$selectorYearStart;
	$selector.="</select>&nbsp;";
	$selector.="&nbsp;&nbsp;".$lang["to"].":&nbsp;";
	$selector.="<select name=\"dayEnd\">";
	$selector.=$selectorDayEnd;
	$selector.="</select>.";
	$selector.="<select name=\"monthEnd\">";
	$selector.=$selectorMonthEnd;
	$selector.="</select>.";
	$selector.="<select name=\"yearEnd\">";
	$selector.=$selectorYearEnd;
	$selector.="</select>&nbsp;&nbsp;";

	$selector.="<input type=\"submit\" class=\"sapidcms_cont_btn\" value=\"".$lang["Show"]."\">";
	$selector.="</div></form>";

	$image = "<div><img src=\"".$env["http_path"]."etc/interface/graph.php?picMode=".$graphMode."&title=Site: ".$env["http_path"]."\" width=\"600\" height=\"400\" /></div>";
	$panel=$selector.$image.$cn."<div style='height: 50px'>&nbsp;</div>";

}
$week_start = date("Y.m.d", time()-6*24*60*60);
$top_menu = "<div style=\"padding: 5px 20px; background: #A2C3D8\"><a style=\"font-size: 12px\" href=\"".$env["http_path"]."?option=stats&table=true\">".$lang["DailyReport"]."</a> |
<a style=\"font-size: 12px\" href=\"".$env["http_path"]."?option=stats&date_start=".$week_start."\">".$lang["general_report"]."</a> | 
<a style=\"font-size: 12px\" href=\"".$env["http_path"]."?option=stats&graph=true\">".$lang["Diagrams"]."</a></div>";
$panel=$top_menu.$panel;
?>